package com.itheima.controller;

import com.itheima.domain.Book;
import com.sun.org.apache.xpath.internal.operations.Bool;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;

@Controller
public class BookController {
    @RequestMapping("/showPageAndData1")
    public String showPageAndData1(HttpServletRequest request) {
        request.setAttribute("name","SpringMVC入门案例");
        request.setAttribute("price",66.66d);
        return "page";
    }
    @RequestMapping("/showPageAndData2")
    public String showPageAndData2(Model model){
        model.addAttribute("name","itheima");
        Book book = new Book();
        book.setName("SpringMVC入门实战");
        book.setPrice(66.6d);
        model.addAttribute("book",book);
        return "page";
    }
    @RequestMapping("/showPageAndData3")
    public ModelAndView showPageAndData3(ModelAndView modelAndView){
        Book book = new Book();
        book.setName("SpringMVC入门实战");
        book.setPrice(66.6d);
        modelAndView.addObject("book",book);
        modelAndView.addObject("name","jockme");
        modelAndView.setViewName("page");
        return modelAndView;
    }
}
